package basic

import (
	"fmt"
	"time"
	"math"
	"go-tour/tourx"
	"math/rand"
)

var c, python, java bool
var i, j int = 1, 2

const Pi = 3.14

const (
	// Create a huge number by shifting a 1 bit left 100 places.
	// In other words, the binary number that is 1 followed by 100 zeroes.
	Big = 1 << 100
	// Shift it right again 99 places, so we end up with 1<<1, or 2.
	Small = Big >> 99
)

const (
	c1 = iota
	c2
	c3
)

const (
	GB01 = iota
	GB02
	GB03
)

func Basic() {
	fmt.Println("My favorite number is", rand.Intn(10))

	//rand seed
	rand.Seed(time.Now().UnixNano())
	fmt.Println("My favorite number is", rand.Intn(100))

	fmt.Printf("Now you have %g problems.\n", math.Sqrt(7))
	fmt.Println(math.Pi)
	tourx.ExportX()

	fmt.Println(add(42, 13))

	a, b := swap("hello", "world")
	fmt.Println(a, b)
	fmt.Println(split(17))

	var i int
	fmt.Println(i, c, python, java)

	var c, python, java = true, false, "no!"
	fmt.Println(i, j, c, python, java)

	k := 3
	c0, python0, java0 := true, false, "no!"

	fmt.Println(i, j, k, c0, python0, java0)

	var x, y int = 3, 4
	var f float64 = math.Sqrt(float64(x * x + y * y))
	var z uint = uint(f)
	fmt.Println(x, y, z)

	v := 42 // change me!
	fmt.Printf("v is of type %T\n", v)

	const World = "世界"
	fmt.Println("Hello", World)
	fmt.Println("Happy", Pi, "Day")

	const Truth = true
	fmt.Println("Go rules?", Truth)

	fmt.Println(needInt(Small))
	fmt.Println(needFloat(Small))
	fmt.Println(needFloat(Big))

	fmt.Println(c1)
	fmt.Println(c2)
	fmt.Println(c3)

	fmt.Println(GB01)
}

func add(x int, y int) int {
	return x + y
}

func add0(x, y int) int {
	return x + y
}

func swap(x, y string) (string, string) {
	return y, x
}

func split(sum int) (x, y int) {
	x = sum * 4 / 9
	y = sum - x
	return
}

func needInt(x int) int {
	return x * 10 + 1
}
func needFloat(x float64) float64 {
	return x * 0.1
}
